package ru.ipo.dces.plugins.admin.resultstable;

import javax.swing.table.TableCellRenderer;
import java.util.*;

/**
 * Created by IntelliJ IDEA.
 * User: ilya
 * Date: 29.03.11
 * Time: 19:41
 */
public class KeySetsRegistry {

    private static KeySetsRegistry ourInstance = new KeySetsRegistry();

    public static KeySetsRegistry getInstance() {
        return ourInstance;
    }

    private KeySetsRegistry() {
    }

    //instance data

    private HashMap<Set<String>, KeySet> set2obj = new HashMap<Set<String>, KeySet>();

    public void registerKeySet(String[] set, TableCellRenderer renderer) {
        Set<String> keys = new HashSet<String>();
        keys.addAll(Arrays.asList(set));
        KeySet ks = new KeySet(keys, renderer);
        set2obj.put(keys, ks);
    }

    public void registerKeySet(String[] set) {
        registerKeySet(set, null);
    }

    public KeySet getKeySet(String[] set) {
        Set<String> keys = new HashSet<String>();
        keys.addAll(Arrays.asList(set));

        return set2obj.get(keys);
    }

    public KeySet getKeySet(Set<String> set) {
        return set2obj.get(set);
    }
}
